package leesoft.toolbox;

import java.util.logging.Logger;

import leesoft.hub.actions.IAction;

public class ServletTool {
	public static String getActionName(String requestPath,String contextPath,String servletPath){
		String actionName=requestPath;
		actionName=actionName.replaceFirst(contextPath, "").replaceFirst(servletPath, "");
		if(actionName.equals(""))
			return "";
		else
			return actionName.substring(1);
	}
	public static IAction getActionProcessor(String actionName){
		String className=StringTool.doAbc(actionName);
		String prefix=PropertyManager.getInstance().getValue("hub.action.prefix");
		String postfix=PropertyManager.getInstance().getValue("hub.action.postfix");
		Logger.getAnonymousLogger().info("prefix:"+prefix);
		try{
			return (IAction)Class.forName(prefix+"."+className+postfix).newInstance();
		}catch(Exception e){
			Logger.getAnonymousLogger().info("Unable to load the action");
			e.printStackTrace();
			return null;
		}
	}
}
